﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;

namespace QuanLyKhachSan
{
    public class PhongDAL
    {
        public PhongDAL()
        {

        }
        public void Phong_Add(int LoaiPhongId,string PhongName,int TienNghiID,int SoGiuong,int SoNguoi)
        {
            SQLDataHelper SQLDB = new SQLDataHelper();
            SQLDB.Addparameter("@LoaiPhongId", LoaiPhongId);
            SQLDB.Addparameter("@PhongName", PhongName);
            SQLDB.Addparameter("@TienNghiID", TienNghiID);
            SQLDB.Addparameter("@SoGiuong", SoGiuong);
            SQLDB.Addparameter("@SoNguoi", SoNguoi);
            SQLDB.executenonquery("sp_Phong_Add", CommandType.StoredProcedure);                        
        }
        public void Phong_Edit(int PhongID, int LoaiPhongId, string PhongName, int TienNghiID, int SoGiuong, int SoNguoi)
        {
            SQLDataHelper SQLDB = new SQLDataHelper();
            SQLDB.Addparameter("@PhongID", PhongID);
            SQLDB.Addparameter("@LoaiPhongId", LoaiPhongId);
            SQLDB.Addparameter("@PhongName", PhongName);
            SQLDB.Addparameter("@TienNghiID", TienNghiID);
            SQLDB.Addparameter("@SoGiuong", SoGiuong);
            SQLDB.Addparameter("@SoNguoi", SoNguoi);
            SQLDB.executenonquery("sp_Phong_Edit", CommandType.StoredProcedure);
        }
        public void Phong_Delete(int PhongID)
        {
            SQLDataHelper SQLDB = new SQLDataHelper();
            SQLDB.Addparameter("@PhongID", PhongID);
            SQLDB.executenonquery("sp_Phong_Delete", CommandType.StoredProcedure);
        }
        public PhongInfo Phong_GetItem(int PhongID)
        {
            SQLDataHelper SQLDB = new SQLDataHelper();
            SQLDB.Addparameter("@PhongID", PhongID);
             SqlDataReader rd = SQLDB.executereader("sp_Phong_GetItem", CommandType.StoredProcedure);
             PhongInfo item = null;
            while (rd.Read())
            {
                item = new PhongInfo();
                item.PhongID = int.Parse(rd["PhongID"].ToString());
                item.PhongName = rd["PhongName"].ToString();
                item.LoaiPhongID = int.Parse(rd["LoaiPhongID"].ToString());
                item.TienNghiID = int.Parse(rd["TienNghiID"].ToString());
                item.SoGiuong = int.Parse(rd["SoGiuong"].ToString());
                item.SoNguoi = int.Parse(rd["SoNguoi"].ToString());

            }
            return item;
        }
        public List<PhongInfo> Phong_GetItems()
        {
            SQLDataHelper SQLDB = new SQLDataHelper();
            SqlDataReader rd = SQLDB.executereader("sp_Phong_GetItems", CommandType.StoredProcedure);
            List<PhongInfo> list = new List<PhongInfo>();
            PhongInfo item = null;
            while (rd.Read())
            {
                item = new PhongInfo();
                item.PhongID = int.Parse(rd["PhongID"].ToString());
                item.PhongName = rd["PhongName"].ToString();
                item.LoaiPhongID = int.Parse(rd["LoaiPhongID"].ToString());
                item.LoaiPhongName = rd["LoaiPhongName"].ToString();
                item.SoGiuong = int.Parse(rd["SoGiuong"].ToString());
                item.SoNguoi = int.Parse(rd["SoNguoi"].ToString());
                item.TienNghiName = rd["TienNghiName"].ToString();
                list.Add(item);
            }
            return list;
        }
    }
}

